package com.xiangge.abstract1;

interface Fightable {
    void attack(Fightable target);
    void fightOver(Fightable winner);
}

class Hero implements Fightable {
    private static final int MIN_BLOOD = 0;
    private String name;
    private int level;
    private int experience;
    private int blood;

    public Hero(String name, int level, int experience, int blood) {
        this.name = name;
        this.level = level;
        this.experience = experience;
        this.blood = blood;
    }

    @Override
    public void attack(Fightable target) {
        if (target instanceof Hero) {
            Hero targetHero = (Hero) target;
            targetHero.blood -= 10;
            if (targetHero.blood < MIN_BLOOD) {
                System.out.println(targetHero.name + " 血液值低于MIN，处于危险状态！");
            }
            this.experience += 5; // 获胜后经验值增加
        }
    }

    // 结束战斗，判断胜负
    @Override
    public void fightOver(Fightable winner) {
        if (winner == this) {
            System.out.println(this.name + " 获胜！");
        } else {
            System.out.println(this.name + " 战败！");
        }
    }

    // 其他getter和setter方法
    // ...

    // 为了测试方便，重写toString方法
    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", level=" + level +
                ", experience=" + experience +
                ", blood=" + blood +
                '}';
    }
}

// 测试类
class AbstractTest51 {
    public static void main(String[] args) {
        Hero hero1 = new Hero("英雄A", 1, 0, 100);
        Hero hero2 = new Hero("英雄B", 1, 0, 100);

        // 模拟英雄A攻击英雄B
        hero1.attack(hero2);
        System.out.println("英雄A攻击后: " + hero1);
        System.out.println("英雄B当前状态: " + hero2);

        // 假设英雄B获胜（这里只是假设，因为上面的attack方法只是减少了英雄B的血液值）
        hero2.fightOver(hero2); // 英雄B调用fightOver方法，并传入自己作为胜利者

        // 更新英雄B的经验值（这里只是假设，因为上面的attack方法已经增加了经验值）
        // hero2.experience += ...; // 省略具体数值

        System.out.println("英雄B获胜后: " + hero2);
    }
}
